﻿using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.Runtime;
using System;

public class CheakOut
{
    [CommandMethod("CheakOut")]
    public void CheakOutMethod()
    {
        // 获取当前文档和编辑器
        Document doc = Application.DocumentManager.MdiActiveDocument;
        Editor ed = doc.Editor;
        Database db = doc.Database;

        // 提示用户选择标注对象
        PromptEntityOptions promptOptions = new PromptEntityOptions("\n请选择一个标注对象：");
        promptOptions.SetRejectMessage("\n选择的对象必须是标注类型。");
        promptOptions.AddAllowedClass(typeof/*(MLeader)*/(Dimension), false);  // 允许所有类型的标注

        // 获取用户选择的对象
        PromptEntityResult promptResult = ed.GetEntity(promptOptions);
        if (promptResult.Status != PromptStatus.OK)
            return;  // 如果没有选择对象，则退出

        // 获取所选对象的 ObjectId
        ObjectId dimensionId = promptResult.ObjectId;

        // 获取标注对象
        using (Transaction tr = db.TransactionManager.StartTransaction())
        {
            Dimension dim = tr.GetObject(dimensionId, OpenMode.ForWrite) as Dimension;
            if (dim == null)
            {
                ed.WriteMessage("\n选择的对象不是标注类型。");
                return;
            }

            // 输出标注对象的类型
            ed.WriteMessage($"\n选中的标注对象类型: {dim.GetType().Name}");



        }
    }
}
